#include "ConveyorBelt.h"

#include "Physics.h"
#include "Time.h"

ConveyorBelt::ConveyorBelt(void)
{
	objectID = "ConveyorBelt";
	positionX = 0;
	positionY = 0;

	isClockwise = true;
	isVertical = false;

	conveyorSpeed = 150.0f;
}


ConveyorBelt::~ConveyorBelt(void)
{
}


void ConveyorBelt::Update(float deltaTime)
{	 
	//ConveyorBelt is stationary

	//Update speed to move objects by for this frame
	//conveyorSpeed = conveyorSpeed * deltaTime;

	//Change direction/isClockwise on switch direction event

}	 
void ConveyorBelt::Render(void) const
{	
	//Conveyor belt is rendered with tiles - this class represents a collision box

	//Switch Direction event changes direction the tiles animate
}	
void ConveyorBelt::HandleCollision(GameObject& other, CollisionInfo& info)
{
	/*if(info.Side == CollisionSide::BOTTOM && this->isVertical == true)
	other.SetPosX(other.GetPosX() + (this->getSpeed() * Time::GetInstance().DeltaTime()));*/
	//other.SetHitBox(Physics::UpdateColRect(other.GetHitBox(), (int)other.GetPosX(), (int)other.GetPosY()));

	if(info.Side == CollisionSide::BOTTOM)
	{
		other.SetPosY( other.GetPosY() - (info.Overlap.bottom - info.Overlap.top));
		if( isClockwise )
			other.SetPosX(other.GetPosX() + (conveyorSpeed * Time::GetInstance().DeltaTime()));
		else
			other.SetPosX(other.GetPosX() - (conveyorSpeed * Time::GetInstance().DeltaTime()));
	}
	if(info.Side == CollisionSide::TOP)
		other.SetPosY( other.GetPosY() + (info.Overlap.bottom - info.Overlap.top));
	if(info.Side == CollisionSide::LEFT)
		other.SetPosX( other.GetPosX() + (info.Overlap.right - info.Overlap.left));
	if(info.Side == CollisionSide::RIGHT)
		other.SetPosX( other.GetPosX() - (info.Overlap.right - info.Overlap.left));

	other.SetHitBox(Physics::UpdateColRect(other.GetHitBox(), (int)(other.GetPosX()), (int)(other.GetPosY())));
}